****APPENDIX TABLE C1****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Generate relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

fegen ccode_survey_year = group(ccode survey_year)
fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample gallup_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
gen gallup_sample = 1 if born_country==1 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup"
replace gallup_sample = 1 if total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

gen gallup_sample_robust = 1 if born_country==1 & total_growth_rate_obs==(age-1) & survey=="Gallup"

//countries with at least approx. 100 years of GDP data from MPD (even before interpolation)
gen complete_data = . 
foreach x in ///
	ARG AUS AUT BEL BGR BOL BRA CAN CHE CHL ///
	COL CRI CUB DEU DNK ECU ESP FIN FRA GBR ///
	GRC GTM HND HUN IDN IND IRL ITA JPN KOR ///
	LKA MEX MYS NIC NLD NOR NZL PAN PER PHL ///
	POL PRT ROU SGP SLV SUN SWE TUR TWN URY ///
	USA VEN YUG ///
	{
		replace complete_data = 1 if ccode=="`x'"
	}

//--------------------------------------------------------
//Create Table C1 (Panel A)
//--------------------------------------------------------

summ wgrowth_rate_1 if sample==1
scalar mean = r(mean)
scalar sd = r(sd)

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, replace dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													      Survey, Harmonized, ///
													      Sample, Outliers) keep(zwgrowth_rate_1) 

//Column 2														  
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country==1 & total_growth_rate_obs==age-1 & survey_year<=2023 & survey_year!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country==1 & total_growth_rate_obs==age-1 & survey_year<=2023 & survey_year!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Harmonized, ///
													     Sample, 100% & Born Country) keep(zwgrowth_rate_1) 

//Column 3														 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Harmonized, ///
													     Sample, All) keep(zwgrowth_rate_1) 													   

//Column 4														
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & complete_data==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & complete_data==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Harmonized, ///
													     Sample, Complete) keep(zwgrowth_rate_1) 

summ wgrowth_rate_1 if gallup_sample==1
scalar mean = r(mean)
scalar sd = r(sd)													   
	
//Column 5	
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, Outliers) keep(zwgrowth_rate_1) 													   

//Column 6														 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample_robust==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample_robust==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, 100% & Born Country) keep(zwgrowth_rate_1) 

//Column 7															 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup", absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup", absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, All) keep(zwgrowth_rate_1) 		
													   

//Column 8														   
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup" & complete_data==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup" & complete_data==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_a.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, Complete) keep(zwgrowth_rate_1) 
														 
//--------------------------------------------------------
//Create Table C1 (Panel B)
//--------------------------------------------------------

summ wgrowth_rate_1 if sample==1
scalar mean = r(mean)
scalar sd = r(sd)

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, replace dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													      Survey, Harmonized, ///
													      Sample, Outliers) keep(zwgrowth_rate_1) 

//Column 2														  
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country==1 & total_growth_rate_obs==age-1 & survey_year<=2023 & survey_year!=., absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country==1 & total_growth_rate_obs==age-1 & survey_year<=2023 & survey_year!=., absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Harmonized, ///
													     Sample, 100% & Born Country) keep(zwgrowth_rate_1) 

//Column 3														 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=., absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=., absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Harmonized, ///
													     Sample, All) keep(zwgrowth_rate_1) 													   

//Column 4														
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & complete_data==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & complete_data==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Harmonized, ///
													     Sample, Complete) keep(zwgrowth_rate_1) 

summ wgrowth_rate_1 if gallup_sample==1
scalar mean = r(mean)
scalar sd = r(sd)
	
//Column 5	
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1 & wgrowth_rate_1>`=scalar(mean)'-2*`=scalar(sd)' & wgrowth_rate_1<`=scalar(mean)'+2*`=scalar(sd)', absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, Outliers) keep(zwgrowth_rate_1) 													   

//Column 6														 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample_robust==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample_robust==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, 100% & Born Country) keep(zwgrowth_rate_1) 

//Column 7															 
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup", absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup", absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, All) keep(zwgrowth_rate_1) 		
													   

//Column 8													   
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup" & complete_data==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
standardize trust_govt
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if born_country!=0 & survey_year<=2023 & survey_year!=. & survey=="Gallup" & complete_data==1, absorb(ccode_survey_year subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_c1_panel_b.doc, append dec(3) nocons addtext(Subcontinent FE x Cohort FE, Yes, ///
													     Survey, Gallup, ///
													     Sample, Complete) keep(zwgrowth_rate_1)	
